// pages/address/address.js
import utils from "../../utils/utils.js";
const app = getApp();

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
    getCouponUrl: '/tiket/getUserTicket',
    couponList: [],
    nonOrder: false
	},
	
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
    this.getCouponData()
	},
  getCouponData () {
    let that = this;
    let indexData = my.getStorageSync({key:'indexData'});
    let _data = {
      url: that.data.getCouponUrl,
      data: {
        userId: indexData.data.user.userId,
        type: indexData.data.user.type
      }
    };
    utils.request.call(_data, (res) => {
      console.log(res);
      if (res.data.status == 200) {
        that.data.couponList = res.data.data;
        if (that.data.couponList.length > 0) {
          for (let i = 0; i < that.data.couponList.length; i++) {
            that.data.couponList[i].lastTime = utils.date(that.data.couponList[i].lastTime);
            that.data.couponList[i].useDate = utils.date(that.data.couponList[i].useDate);
          };
        } else {
            that.data.nonOrder = true;
        };
        that.setData({
          couponList: that.data.couponList,
          nonOrder: that.data.nonOrder
        })
      };
    });
  },

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
